define [
  'jquery', 'knockout', 'mapping', 'underscore', 'DataSource'
], ($, ko, mapping, _, DataSource) ->
  ko.extenders.DataSource = DataSource

  class comboModel
    constructor: (@parent, @data) ->
      mapping.fromJS @data, {}, @

  class viewModel
    constructor: ->
      @rows = ko.observableArray([]).extend {
        DataSource:
          url: 'demo/aaa'
          versionType: 0
          pageType: 1
          setTotalPage: (target, data) ->
            target.totalPage 1
          success: (target, data) =>
            if not data.status
              return false
            target _.map data.data.combos, (combo) =>
              new comboModel @, combo
            true
      }
      @rows.fetch()

  $ ->
    ko.applyBindings new viewModel()